Styler-ify more Credo rules: FilterReject, RejectFilter, MapMap, and and !is_* guards#15
Merged
Conversation
…!is_* guards Adds pipe-collapsing for Enum.filter |> Enum.reject (and the reverse), Enum.map |> Enum.map, and rewrites !is_nil/is_*/etc. to use `not`. Also extends the empty-check rewrite to cover String.length and byte_size.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f20b7ba. Configure here.
byte_size(x) > 0 and x != "" are equivalent and equally efficient on binaries (byte_size reads the size header in O(1), and binary inequality short-circuits on that same header). Neither form is more idiomatic than the other, so there's no clear win to rewriting one to the other. Keep the String.length rewrite, which is a real perf win.
Reported by Cursor Bugbot: the comment on iteration_var_name said "if either side is an inline fn x -> ...", but the function only inspected f1. When f1 was a capture (e.g. &Mod.foo/1) and f2 was fn descriptive_name -> ..., the merged lambda defaulted to :arg1 instead of using f2's more meaningful name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Styler-ify more Credo rules: FilterReject, RejectFilter, MapMap, and !is_* guards
Adds pipe-collapsing for:
Enum.filter |> Enum.reject(and the reverse)Enum.map |> Enum.map, and rewrites!is_nil/is_*/etc. to usenot.String.length.Note
Medium Risk
Medium risk because it expands non-trivial AST transformations (inlining/collapsing
Enum.mapchains and predicate merging), which could subtly change output code shape or edge-case semantics if pattern guards miss cases.Overview
Adds new pipe-collapsing rewrites in
Styler.Style.PipesforEnum.filter |> Enum.rejectandEnum.reject |> Enum.filter, plus a newEnum.map |> Enum.mapmerge that inlines captures/1-arity lambdas into a singleEnum.mapwith a piped body (with safeguards to skip unsafe inlining/variable-shadowing cases).Enhances predicate combination to support optional negation, and introduces helper logic for capture/lambda inlining and pipifying nested calls.
Updates
Styler.Style.SingleNodeto rewrite!is_*guard-style predicates tonot is_*, and extends the “expensive empty check” rewrite to handleString.length(x) <op> 0|1via comparisons against"". Documentation and tests are updated to reflect the newly covered Credo rules and behaviors.Reviewed by Cursor Bugbot for commit 33551cc. Bugbot is set up for automated code reviews on this repo. Configure here.